import urllib.request
import urllib.parse

url = 'http://www.baidu.com/s?wd=ip'
headers={
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36"
,"Cookie":"BAIDUID=61DE5B3752CCC2FA8652E9AB276B49F4:FG=1; BIDUPSID=61DE5B3752CCC2FA8652E9AB276B49F4; PSTM=1716729875; BDUSS=1ZaYnFFVlFMNElHZm5yaW0wOX5LenNKR0NwVmNJYWJIVkd2eHpqa0p-cGpJcEZtSVFBQUFBJCQAAAAAAQAAAAEAAAASQI9ax6vO918AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGOVaWZjlWlmd; BDUSS_BFESS=1ZaYnFFVlFMNElHZm5yaW0wOX5LenNKR0NwVmNJYWJIVkd2eHpqa0p-cGpJcEZtSVFBQUFBJCQAAAAAAQAAAAEAAAASQI9ax6vO918AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGOVaWZjlWlmd; H_WISE_SIDS=60326_60337; H_WISE_SIDS_BFESS=60326_60337; BDORZ=FFFB88E999055A3F8A630C64834BD6D0; H_PS_PSSID=60337; delPer=0; BAIDUID_BFESS=61DE5B3752CCC2FA8652E9AB276B49F4:FG=1; BA_HECTOR=0l2l2k8gah2h0g0h0g852g018del7t1j7ipam1u; PSINO=6; ZFY=kNVDyFZpg9GOCSzPtMRjRv1xk4WgLZlPNbsXn8zoQ:Aw:C; BDRCVFR[V3EOV_cRy1C]=mk3SLVN4HKm"
}
# 请求对象定制
request=urllib.request.Request(url=url,headers=headers)

# response=urllib.request.urlopen(request)
# 代理IP    字典形式存在
proxies ={
    'http':'218.87.205.20:15346',
}

handle=urllib.request.ProxyHandler(proxies = proxies)
opener=urllib.request.build_opener(handle)
response=urllib.request.urlopen(request)


content=response.read().decode('utf-8')

# 保存
with open('ip.html','w',encoding='utf-8') as f:
    f.write(content)